package org.sith.taskrunner.ejb.tasks;

import org.sith.taskrunner.api.task.Task;
import org.sith.taskrunner.api.exceptions.TaskExecutionException;
import org.sith.taskrunner.api.exceptions.TaskInitException;

import java.util.List;


public class SumTask implements Task<SumInputData, SumResult>{
    private SumInputData inputData = null;

    @Override
    public void init(SumInputData inputData) throws TaskInitException {
        this.inputData = inputData;
    }


    @Override
    public SumResult executeTask() throws TaskExecutionException {
        Integer result = 0;
        List<Integer> numerics = inputData.getNumerics();
        for (Integer number : numerics) {
            result += number;
        }
        return new SumResult(result);
    }


}
